clear
est clear

	use "$input/full_geoid_pair_panel.dta"
	
	bysort state_fips: egen max=max(storm)
		drop if max!=1

	replace migration=migration/(tot_pop/100000)
	
			
	preserve
		collapse (sum) migration ,by(to_geoid move_year )

			rename migration in_migration
			rename to_geoid from_geoid
			save "$input/temp1.dta", replace
	restore
	
	
		collapse (sum) migration ,by(from_geoid move_year storm state_fips)
	
		merge 1:1 from_geoid move_year using "$input/temp1.dta"
		
		g net_migration=in_migration-migration
		
		g count=1 if net_migration!=.
		
		bysort from_geoid: egen total=total(count)
			drop if total!=27
			drop count total
		
		collapse (sum) net_migration storm, by(from_geoid)
		
		egen mean_storm=mean(storm)
		egen sd_storm=sd(storm)
		egen mean_mig=mean(net)
		egen sd_mig=sd(net)
		g z_storm=(storm-mean_storm)/sd_storm
		g z_mig=(net-mean_mig)/sd_mig
			
		twoway (scatter z_mig z_storm ,m(C) mc(navy%10)) ///
						(lfit z_mig z_storm , lc(gs4) lp(dash) ///
						yti("Z-score of total net migration", size(large)) xtitle("Z-score of total storms", size(large)) xlab(, nogrid labsize(vlarge)) ylabel(,nogrid labsize(vlarge)) ysize(12) xsize(12) legend(off))	
						
		graph export "$figures/fig_3b.png", as(png) replace
	
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			